package com.tnovoselec.server.travelassistant;
import java.io.File;
import java.util.Date;
import java.util.Timer;

import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;

import com.tnovoselec.server.travelassistant.worker.RefreshCache;

public class Main {
	
	private static Timer timer;

    public static void main(String[] args) throws Exception {

        String webappDirLocation = "/usr/local/TravelAssistant/server/war/";
        Tomcat tomcat = new Tomcat();

      
        String webPort = System.getenv("PORT");
        if(webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        tomcat.setPort(Integer.valueOf(webPort));

        tomcat.addWebapp("", webappDirLocation);
//        Connector connector = new Connector();
//        connector.setAttribute("compression", "on");
//        connector.setAttribute("compressionMinSize","2048");
//        connector.setAttribute("noCompressionUserAgents","gozilla, traviata");
//        connector.setAttribute("compressableMimeType","text/html,text/xml");
//        tomcat.setConnector(connector);
        System.out.println("configuring app with basedir: " + new File("/usr/local/TravelAssistant/server/" + webappDirLocation).getAbsolutePath());

        
        timer = new Timer();
        timer.schedule(new RefreshCache(), new Date(), 10*60*1000);
        
        tomcat.start();
        tomcat.getServer().await();  
     
        
    }
}
